package org.apm.data.copy;

import org.apm.data.bean.ScrollBean;
import org.apm.data.util.StringUtil;
import org.elasticsearch.action.bulk.BulkProcessor;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.Client;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.SearchHit;

public class CopyScrollBean extends ScrollBean {

    public CopyScrollBean(Client client, BulkProcessor bulkProcessor, String index, QueryBuilder query) {
        super(client, bulkProcessor, index, query);
    }

    @Override
    public void processData(SearchHit hit) {
        String indexName = hit.getIndex();
        if (StringUtil.isExist(getDst_index())) {
            indexName = getDst_index();
        }

        IndexRequest index = new IndexRequest().index(indexName).type(hit.getType()).id(hit.id()).source(hit.getSource());
        getBulkProcessor().add(index);
    }
}
